package com.geotmt.billingcenter.modules.cost.service.impl;

import com.geotmt.billingcenter.common.entry.CostBaseHisEntry;
import com.geotmt.billingcenter.common.enumpackage.CostFeeFlagEnum;
import com.geotmt.billingcenter.common.enumpackage.RuleLabelEnum;
import com.geotmt.billingcenter.common.vo.cost.CostHisVo;
import com.geotmt.billingcenter.common.vo.params.ParamsCost;
import com.geotmt.billingcenter.common.vo.params.ParamsForDel;
import com.geotmt.billingcenter.modules.cost.mapper.CostBaseHisMapper;
import com.geotmt.billingcenter.modules.cost.service.CostBaseHisService;
import com.geotmt.billingcenter.modules.rules.service.RulesService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @Description 成本 baseHis service
 * @Author      yanghanwei
 * @Mail        yanghanwei@geotmt.com
 * @Date        2019/3/20 11:37
 * @Version     v1
 **/
@Service
@Transactional(rollbackFor = Exception.class)
public class CostBaseHisServiceImpl implements CostBaseHisService {

    private static final Logger logger = LoggerFactory.getLogger(CostBaseHisServiceImpl.class);

    @Resource
    private CostBaseHisMapper costBaseHisMapper;

    @Resource
    private RulesService rulesService;

    @Override
    public Integer addBaseHis(CostBaseHisEntry costBaseHis) {
        logger.info("cost add BaseHis");
        costBaseHisMapper.addBaseHis(costBaseHis);
        return costBaseHis.getId();
    }

    @Override
    public void deleteBaseHis(ParamsForDel obj) {
        logger.info("cost delete BaseHis");
        costBaseHisMapper.deleteBaseHis(obj);
    }

    @Override
    public List<CostHisVo> listHis(ParamsCost obj) {
        logger.info("cost listHis");
        List<CostHisVo> costHisVos = costBaseHisMapper.listHis(obj);
        if(null != costHisVos){
            for(CostHisVo costHisVo : costHisVos){
                if(CostFeeFlagEnum.STAIR.value.equals(costHisVo.getFeeFlag())){
                    costHisVo.setStairRuleList(rulesService.stairListGetByRid(costHisVo.getRId(), RuleLabelEnum.COST_HIS.value));
                }
            }
        }
        return costHisVos;
    }

    @Override
    public void updateEndEffect(Date preDay, Integer id) {
        logger.info("更新有效结束时间");
        costBaseHisMapper.updateEndEffect(preDay, id);
    }
}
